<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="投诉人" prop="lvTsPl">
            <el-input
              v-model="queryParams.lvTsPl"
              placeholder="请输入投诉人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="申请流水号" prop="lvSl">
            <el-input
              v-model="queryParams.lvSl"
              placeholder="请输入申请流水号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="投诉人电话" prop="lvTsTel">
            <el-input
              v-model="queryParams.lvTsTel"
              placeholder="请输入投诉人电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="来源" prop="lvSource">
            <el-input
              v-model="queryParams.lvSource"
              placeholder="请输入来源"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="投诉单位" prop="lvTsEp">
            <el-input
              v-model="queryParams.lvTsEp"
              placeholder="请输入投诉单位"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="污染类型" prop="lvPtType">
            <el-select v-model="queryParams.lvPtType" placeholder="请选择污染类型" clearable size="small">
              <el-option label="请选择字典生成" value="" />
            </el-select>
          </el-form-item>
          <el-form-item label="信访时间" prop="lvStTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.lvStTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择信访时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="受理状态" prop="lvIsAccept">
            <el-input
              v-model="queryParams.lvIsAccept"
              placeholder="请输入受理状态"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="办理状态(0审核中 1 调查中 2整改中 3 已完成)" prop="lvDealState">
            <el-input
              v-model="queryParams.lvDealState"
              placeholder="请输入办理状态(0审核中 1 调查中 2整改中 3 已完成)"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="处理结果" prop="lvDealResult">
            <el-input
              v-model="queryParams.lvDealResult"
              placeholder="请输入处理结果"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="公示状态" prop="lvIsPub">
            <el-input
              v-model="queryParams.lvIsPub"
              placeholder="请输入公示状态"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="企业ID" prop="epId">
            <el-input
              v-model="queryParams.epId"
              placeholder="请输入企业ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="照片" prop="lvPic">
            <el-input
              v-model="queryParams.lvPic"
              placeholder="请输入照片"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="照片" prop="lvAcceptP">
            <el-input
              v-model="queryParams.lvAcceptP"
              placeholder="请输入照片"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['visit:letter:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visit:letter:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visit:letter:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['visit:letter:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="letterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="ID" align="center" prop="lvId" />-->
      <el-table-column label="投诉人" align="center" prop="lvTsPl"/>
      <!--      <el-table-column label="申请流水号" align="center" prop="lvSl" />-->
      <el-table-column label="投诉人电话" align="center" prop="lvTsTel"/>
      <!--      <el-table-column label="来源" align="center" prop="lvSource" />-->
      <el-table-column label="投诉单位" align="center" prop="lvTsEp"/>
      <el-table-column label="污染类型" align="center" prop="lvPtType">
        <template slot-scope="scope" v-if="scope.row.lvPtType">
          <div v-if="scope.row.lvPtType == 0">水污染</div>
          <div v-if="scope.row.lvPtType == 1">固体污染</div>
          <div v-if="scope.row.lvPtType == 2">噪声污染</div>
          <div v-if="scope.row.lvPtType == 3">大气污染</div>
        </template>
      </el-table-column>
      <el-table-column label="投诉内容" align="center" prop="lvTsCt"/>
            <el-table-column label="信访时间" align="center" prop="lvStTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.lvStTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
      <el-table-column label="受理状态" align="center" prop="lvIsAccept">
        <template slot-scope="scope">
          <span v-if="scope.row.lvIsAccept==0" style="color: #004d8c"> 未受理  </span>
          <span v-if="scope.row.lvIsAccept==1" style="color: red"> 已受理  </span>
          <span v-if="scope.row.lvIsAccept==2" style="color: red"> 已完成 </span>
        </template>
      </el-table-column>
      <el-table-column label="办理状态" align="center" prop="lvDealState">
        <template slot-scope="scope">
          <span v-if="scope.row.lvDealState == 0" style="color: #004d8c">等待处理</span>
          <span v-if="scope.row.lvDealState == 1" style="color: red">调查整改中</span>
          <span v-if="scope.row.lvDealState == 2">等待审批</span>
          <span v-if="scope.row.lvDealState == 3">审核通过</span>
          <span v-if="scope.row.lvDealState == 4">驳回</span>
          <span v-if="scope.row.lvDealState == 5">已完成</span>
        </template>
      </el-table-column>
          <el-table-column label="处理结果" align="center" prop="lvDealResult" />
<!--          <el-table-column label="公示状态" align="center" prop="lvIsPub">
            <template slot-scope="scope">
              <span v-if="scope.row.lvIsPub == 0" style="color: #004d8c">公示</span>
              <span v-if="scope.row.lvIsPub == 1" style="color: red">调查整改中</span>
            </template>
          </el-table-column>-->
      <!--    <el-table-column label="企业ID" align="center" prop="epId" />-->
<!--            <el-table-column label="" align="center" prop="remark" />-->
<!--            <el-table-column label="照片" align="center" prop="lvPic" />-->
<!--      <el-table-column label="审批人" align="center" :formatter="statusFormat">

      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasRole="['zhiban']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasRole="['zhiban']"
          >删除
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==3"
            size="small"
            @click="zhifa_add(scope.row)"
            v-hasRole="['jiancha']"
          >指派
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==2"
            size="small"
            @click="tongyi(scope.row)"
            v-hasRole="['jiancha']"
          >同意
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==2"
            size="small"
            @click="bohui(scope.row)"
            v-hasRole="['jiancha']"
          >驳回
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==0"
            size="small"
            @click="shenpi(scope.row)"
            v-hasRole="['zhiban']"
          >上报
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==0"
            size="small"
            @click="chuli(scope.row)"
            v-hasRole="['zhifa']"
          >接受并处理
          </el-button>
          <el-button
            v-if="scope.row.lvDealState==1"
            size="small"
            @click="huikui(scope.row)"
            v-hasRole="['zhifa']"
          >填报处理结果
          </el-button>
          <el-button
            v-if="(scope.row.lvDealResult) && (scope.row.remark==null)"
            size="small"
            @click="huifang(scope.row)"
            v-hasRole="['zhifa']"
          >回访记录
          </el-button>
          <el-button
            v-if="scope.row.remark"
            size="small"
            @click="gongshi(scope.row)"
          >公示
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="zf_open" width="500px" append-to-body>
      <el-form ref="zf_form" :model="zf_form" :rules="rules" label-width="80px">
        <el-form-item label=" 执法大队人员列表">
          <!--              <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>-->
          <el-checkbox v-model="checked" @change="checkedAll">全选/全不选</el-checkbox>
          <el-tree
            :data="data"
            show-checkbox
            default-expand-all
            :default-checked-keys="selectArr"
            node-key="id"
            ref="vuetree"
            class="tree-border"
            highlight-current
            @check-change="handleCheckChange"
            :props="defaultProps">
          </el-tree>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
        <el-button type="primary" @click="zhifa">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改信访投诉对话框 -->
    <el-dialog :title="title" :visible.sync="add_open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="投诉人" prop="lvTsPl" >
          <el-input v-model="form.lvTsPl" placeholder="请输入投诉人" :readonly="x1" />
        </el-form-item>
        <el-form-item label="电话" prop="lvTsTel" >
          <el-input v-model="form.lvTsTel" placeholder="请输入投诉人电话" :readonly="x1"/>
        </el-form-item>
        <el-form-item label="来源" prop="lvSource" >
          <el-select v-model="lvSIndex" clearable placeholder="请选择" style="width: 100%;"
                     @change="lvSChange" :disabled="x2">
            <el-option v-for="item in lvS" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="投诉单位" prop="lvTsEp" >
          <el-input v-model="form.lvTsEp" placeholder="请输入投诉单位" :readonly="x1"/>
        </el-form-item>
        <el-form-item label="污染类型" prop="lvPtType" >
          <div style="width: 100%;">
            <el-select v-model="rsvIndex" clearable placeholder="请选择" style="width: 100%;"
                       @change="rsvChange" :disabled="x2">
              <el-option v-for="item in rsv" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="投诉内容" prop="lvTsCt"  >
          <el-input v-model="form.lvTsCt" type="textarea" placeholder="请输入内容" :readonly="x1"/>
        </el-form-item >
        <el-form-item label="投诉时间" prop="lvStTime" >
          <el-date-picker clearable size="small"
                          v-model="form.lvStTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择投诉时间" :readonly="x1">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理结果" prop="lvDealResult" v-show="x1">
          <el-input v-model="form.lvDealResult" placeholder="请输入处理结果" :readonly="chuliShow"/>
        </el-form-item>
        <el-form-item label="回访记录" prop="remark" v-show="x3">
          <FileUpload v-model="form.remark"/>
        </el-form-item>
        <!--
            <el-form-item label="公示状态" prop="lvIsPub">
                <el-input v-model="form.lvIsPub" placeholder="请输入公示状态" />
            </el-form-item>
        -->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="add_info" width="1000px">
      <el-row :gutter="20">
        <!--部门数据-->
        <el-col :span="4" :xs="24">
          <div class="head-container">
            <el-input
              v-model="deptName"
              clearable
              placeholder="请输入部门名称"
              prefix-icon="el-icon-search"
              size="small"
              style="margin-bottom: 20px"
            />
          </div>
          <div class="head-container">
            <el-tree
              ref="tree"
              :data="deptOptions"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              :props="defaultProps"
              default-expand-all
              @node-click="handleNodeClick"
            />
          </div>
        </el-col>

        <el-col :span="20" :xs="24">
          <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange2"
                    @current-change="currentChange" ref="Table">
            <el-table-column align="center" type="selection" width="50"/>
            <!--            <el-table-column v-if="columns[0].visible" key="userId" align="center" label="用户编号" prop="userId"/>-->
            <el-table-column v-if="columns[1].visible" key="userName" :show-overflow-tooltip="true" align="center"
                             label="用户名称"
                             prop="userName"/>
            <el-table-column v-if="columns[2].visible" key="nickName" :show-overflow-tooltip="true" align="center"
                             label="用户昵称"
                             prop="nickName"/>
            <el-table-column v-if="columns[3].visible" key="deptName" :show-overflow-tooltip="true" align="center"
                             label="部门"
                             prop="dept.deptName"/>
            <el-table-column v-if="columns[4].visible" key="phonenumber" align="center" label="手机号码" prop="phonenumber"
                             width="120"/>

          </el-table>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center">
        <el-button :type="isColor?'primary':'info'" @click="examine">提交审批</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {addLetter, delLetter, exportLetter, getLetter, listLetter, updateLetter} from "@/api/visit/letter";
import {listUser,getUser} from "@/api/system/user";
import {allocatedUserList} from "@/api/system/role";
import {treeselect} from "@/api/system/dept";
import {validatePhoneTwo} from "@/api/validate/validate";


export default {
  name: "Letter",
  inject:['reload'],
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      infoMation: "",
      add_info: false,
      deptOptions: "",
      isColor: false,
      // 日期范围
      dateRange: [],
      userList: "",
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      sysUser: {
        roleId:'',
      },
      // 列信息
      columns: [
        {key: 0, label: `用户编号`, visible: true},
        {key: 1, label: `用户名称`, visible: true},
        {key: 2, label: `用户昵称`, visible: true},
        {key: 3, label: `部门`, visible: true},
        {key: 4, label: `手机号码`, visible: true},
        {key: 5, label: `状态`, visible: true},
        {key: 6, label: `创建时间`, visible: true}
      ],
      checked: false,
      deptName: "",
      userName: '',
      data: [],
      selectArr: [],
      rsv: [
        {
          value: '0',
          label: '水污染'
        },
        {
          value: '1',
          label: '固体污染'
        },
        {
          value: '2',
          label: '噪声污染'
        },
        {
          value: '3',
          label: '气体污染'
        }
      ],
      rsvIndex: '0',
      lvS: [
        {
          value: '0',
          label: '来电'
        },
        {
          value: '1',
          label: '来访'
        },
      ],
      lvSIndex: '0',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信访投诉表格数据
      letterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      add_open: false,
      zf_open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lvTsPl: null,
        lvSl: null,
        lvTsTel: null,
        lvSource: null,
        lvTsEp: null,
        lvPtType: null,
        lvTsCt: null,
        lvStTime: null,
        lvIsAccept: null,
        lvDealState: null,
        lvDealResult: null,
        lvIsPub: null,
        epId: null,
        lvPic: null,
        lvAcceptP: null
      },
      // 表单参数
      form: {},
      zf_form: {},
      // 表单校验
      rules: {
        lvTsPl: [
          {required: true, message: "请输入投诉人", trigger: "blur"}
        ],
        lvTsTel: [
          {validator: validatePhoneTwo, trigger: "blur"}
        ],
      },
      lvId:'',
      lvUserName:'',
      x1:false,
      x2:false,
      x3:false,
      chuliShow:false,
    };
  },
  created() {
    this.getList();
    //this.getUser();
    //this.getTreeselect();
    //this.getlistUser();
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  methods: {
    statusFormat:function(row, column) {
      //let lvAcceptP = row.lvAcceptP;
      /*if(row.lvAcceptP){
        let userId = parseInt(row.lvAcceptP);
        getUser(userId).then(res=>{
          this.lvUserName = res.data.nickName;
        })
        row.lvAcceptP = this.lvUserName;
      }*/
      if(row.lvAcceptP){
        row.lvAcceptP = 'jiancha';
      }
      return row.lvAcceptP;
    },
    getUser() {
      this.sysUser.roleId = 101;
     /* allocatedUserList(this.sysUser).then(res => {
        console.log(res);
      })*/
      allocatedUserList(this.sysUser).then(res => {
        //console.log(res)
        var list = res.rows;
        var arr = [];
        var index = 0;
        list.map(function (item) {
          var value = {
            id: item.userId,
            label: item.nickName,
          }
          arr.push(value)
        })
        this.data = arr;
      })
    },
    zhifa_add(row) {
      this.getUser();
      this.zf_open = true;
      this.infoMation = row;
      if (row.lvAcceptP) {
        var arr = row.lvAcceptP.split(",");
        this.selectArr = arr;
      } else {
        this.selectArr = [];
      }
    },
    zhifa() {
      console.log(11111111111111111)
      if (this.userName == "") {
        this.msgSuccess("请选择用户");
        return;
      }
      this.infoMation.lvAcceptP = this.userName;
      this.infoMation.lvDealState = 1;
      updateLetter(this.infoMation).then(response => {
        this.msgSuccess("指派成功");
        this.zf_open = false;
        this.getList();
      });
    },
    checkedAll() {
      if (this.checked) {
        //全选
        this.$refs.vuetree.setCheckedNodes(this.data);
      } else {
        //取消选中
        this.$refs.vuetree.setCheckedKeys([]);
      }
    },
    handleCheckChange(data, checked) {
      var arr = this.$refs.vuetree.getCheckedNodes();
      if (arr) {
        var usrArr = [];
        for (var i = 0; i < arr.length; i++) {
          usrArr.push(arr[i].id);
        }
        var name = usrArr.join(",");
        this.userName = name;
        //this.form.lvAcceptP = name;
        this.form.lvIsAccept = 1;
        this.form.lvDealState = 1;
        this.form.lvId = this.lvId;
      } else {
        this.form.lvDealState = 0;
      }
    },
    rsvChange(e) {
      this.form.lvPtType = e;
    },
    lvSChange(e) {
      this.form.lvSource = e;
    },
    /** 查询信访投诉列表 */
    getList() {
      this.loading = true;
      listLetter(this.queryParams).then(res => {
        this.letterList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.add_open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        lvId: null,
        lvTsPl: null,
        lvSl: null,
        lvTsTel: null,
        lvSource: null,
        lvTsEp: null,
        lvPtType: null,
        lvTsCt: null,
        lvStTime: null,
        lvIsAccept: null,
        lvDealState: null,
        lvDealResult: null,
        lvIsPub: null,
        epId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        lvPic: null,
        lvAcceptP: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.add_open = true;
      this.title = "添加信访投诉";
      this.form.lvPtType = this.rsv[this.rsvIndex].value
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const lvId = row.lvId || this.ids
      getLetter(lvId).then(response => {
        this.form = response.data;
        this.add_open = true;
        this.title = "修改信访投诉";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.lvId != null) {
            if(this.form.lvDealResult!=null){
              this.form.lvIsAccept = 2; //已完成
              this.form.lvDealState = 5; // 完成
              updateLetter(this.form).then(response => {
                this.msgSuccess("处理完成");
                this.add_open = false;
                this.getList();
              });
            }else{
              updateLetter(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.add_open = false;
                this.getList();
              });
            }
          } else {
            addLetter(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.add_open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const lvIds = row.lvId || this.ids;
      this.$confirm('是否确认删除信访投诉编号为"' + lvIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delLetter(lvIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有信访投诉数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportLetter(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams2.deptId = data.id;
      this.getlistUser();
    },
    handleSelectionChange() {
    },
    // 多选框选中数据
    handleSelectionChange2(selection) {
      if (selection.length > 0) {
        this.isColor = true;
      } else {
        this.isColor = false;
      }
      if (selection.length > 1) {
        this.$refs.Table.clearSelection()
        this.$refs.Table.toggleRowSelection(selection.pop())

        // this.ids=selection[0].userId

      } else {
        this.ids = selection[0].userId

      }

      // this.ids = selection.map(item => item.userId)
      // this.single = selection.length!==1
      // this.multiple = !selection.length

    },
    currentChange(currentRow, oldCurrentRow) {
      this.$refs.Table.toggleRowSelection(currentRow)
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 查询部门
    getlistUser() {
      listUser(this.addDateRange(this.queryParams2, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    shenpi(row) {
      this.getTreeselect();
      this.getlistUser();
      this.add_info = true;
      this.infoMation = row;
    },
    //上报
    examine() {
      if (!this.isColor) {
        return;
      }
      var idList = this.ids;
      this.infoMation.lvAcceptP = idList;
      const userId = this.ids;
      this.infoMation.lvDealState = 2; //等待审核
      updateLetter(this.infoMation).then(response => {
        this.msgSuccess("已提交审批");
        this.add_info = false;
        this.zf_open = false;
        this.loading = false;
        window.location.reload();
        // this.getlistUser();
        // this.getList();
      });
    },

    //同意
    tongyi(row){
      this.infoMation = row;
      this.infoMation.lvIsAccept = 1;
      this.infoMation.lvDealState = 3; //审核通过
      updateLetter(this.infoMation).then(response => {
        this.msgSuccess("审核通过");
        this.getList();
      });
    },

    bohui(row){
      this.infoMation = row;
      this.infoMation.lvDealState = 4; //驳回
      updateLetter(this.infoMation).then(response => {
        this.msgSuccess("审核不通过，予以驳回");
        this.getList();
      });
    },

    huikui(row) {
      const lvId = row.lvId || this.ids
      getLetter(lvId).then(response => {
        this.form = response.data;
        this.x1 = true;
        this.x2 = true;
        this.add_open = true;
        this.title = "填报处理结果";
      });
    },

    chuli(row){
      this.infoMation = row;
      this.infoMation.lvIsAccept = 1;
      this.infoMation.lvDealState = 1; //自行通过，进入整改阶段
      updateLetter(this.infoMation).then(response => {
        this.msgSuccess("接受处理");
        this.getList();
      });
    },

    huifang(row){
      const lvId = row.lvId || this.ids
      getLetter(lvId).then(response => {
        this.form = response.data;
        this.x1 = true;
        this.x2 = true;
        this.chuliShow = true;
        this.x3 = true;
        this.add_open = true;
        this.title = "回访记录";
      });
    },

    gongshi(row){
      const lvId = row.lvId || this.ids
      getLetter(lvId).then(response => {
        this.form = response.data;
        this.x1 = true;
        this.x2 = true;
        this.chuliShow = true;
        this.x3 = true;
        this.add_open = true;
        this.title = "公示结果";
      });
    }
  }
};
</script>
<style scoped>
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  background-color: #F56C6C;
}
</style>
